package com.example.es.controller;

import com.example.es.entity.MyEntity;
import com.example.es.service.MyEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/entities")
public class MyEntityController {

    @Autowired
    private MyEntityService service;

    @PostMapping(value = {"/save"})
    public MyEntity save(@RequestBody MyEntity entity) {
        return service.save(entity);
    }

    @GetMapping("/name/{name}")
    public List<MyEntity> findByName(@PathVariable String name) {
        return service.findByName(name);
    }

    @GetMapping(value = {"/findAll"})
    public Iterable<MyEntity> findAll() {
        return service.findAll();
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable String id) {
        service.deleteById(id);
    }
}
